package com.baizhi.innerclassx4;

public class Test01 {

    int i = 5;

    public static void main(String[] args) {
        Pet p = new Dog(); //向上造型
        p.eat();
        int q = 5;


        //创建对象的同时后面跟{} 在{}中重写父类的构造方法，就是匿名内部类
        Pet p2 = new Pet(){


            @Override
            public void eat() {
                System.out.println("小猫在吃鱼");
                //q = 6;
                System.out.println(q);
            }
        };

        p2.setName("喵喵");
        p2.eat();


        //匿名内部类
        Running r = new Running() {
            @Override
            public void run() {

            }
        };

        //这也是匿名内部类
        Person person = new Person() {
        };

        Flying f = new Flying() {
        };

        //普通的类也可以通过匿名内部类的形式来写
        Dog d = new Dog(){};

    }
}
